<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('site_users', function (Blueprint $table) {
            $table->id();
            $table->integer('site_id')->nullable()->unsigned()->default(0)->comment('服务商id');
            $table->string('nickname', 30)->nullable()->comment('用户昵称');
            $table->string('username', 50)->nullable()->comment('账号');
            $table->string('password', 100)->nullable()->comment('密码');
            $table->char('mobile', 11)->nullable()->comment('手机号');
            $table->char('status', 1)->nullable()->default('t')->comment('是否启用 t:是 f:否');
            $table->string('avatar', 255)->nullable()->comment('头像');
            $table->char('is_super', 1)->nullable()->default('f')->comment('是否是当前服务商下的超管t:是f:否');
            $table->dateTime('created_at')->nullable();
            $table->dateTime('updated_at')->nullable();
            $table->dateTime('deleted_at')->nullable();
            $table->unique('mobile', 'uniq_mobile')->nullable();
            $table->index('site_id', 'idx_siteId')->nullable();
            $table->index('username', 'idx_username')->nullable();
        });

        $this->initUser();
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('site_users');
    }

    public function initUser()
    {
        return \Illuminate\Support\Facades\DB::table('site_users')
            ->insert([
                'nickname' => 'super',
                'username' => 'admin',
                'password' => Hash::make('123456'),
                'mobile' => '17777777777',
            ]);
    }
};
